package Stream.终端操作;

import java.util.stream.Stream;

//单词:聚合(基本统计操作)
public class Aggregation {
    public static void main(String[] args) {
        Stream<Integer> integerStream = Stream.of(-1, 1, 2, 3);
        //long count = integerStream.count();
/*     Int流还可以进行sum,avg等操作
        IntStream intStream = integerStream.mapToInt(num -> num);
        int sum = intStream.sum();
        System.out.println(sum);*/
        //reduce(累加器)规约操作功能更加强大
        Integer reduce = integerStream.reduce(0, (a, b) -> a + b);
        System.out.println(reduce);
/*        Optional<Integer> max = integerStream.max
                (Comparator.comparing(integer -> integer));//如果是对象: Comparator.comparingInt(Person::getAge)
        max.ifPresent(System.out::println);*/
    }
}
